package com.zysc.processflow.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zysc.processflow.entity.Person;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 人员表 Mapper 接口
 * </p>
 *
 * @author 正元智慧城市_
 * @since 2022-11-23
 */
@Repository
public interface PersonMapper extends BaseMapper<Person> {


    @Select("SELECT distinct a.* from person a,personorg b,personrole c where a.id = b.personid and a.id = c.personid  and c.roleid = #{roleid} and b.orgid = #{orgid}")
    List<Person> getPersonListByOrgIdAndRoleId(@Param("orgid") String orgid, @Param("roleid") String roleid);

    @Select("select distinct b.* from personorg a LEFT JOIN person b on a.personid = b.id where a.orgid = #{orgid}")
    List<Person> getPersonListByOrgId(@Param("orgid")String orgid);

    List<Person> GetPersonList(IPage<Person> page, @Param("username")String username, @Param("orgid")String orgid, @Param("orgids")List<String> orgids, String orgname);
    @Select("<script>"
            + "select distinct b.* from personorg a LEFT JOIN person b on a.personid = b.id where a.orgid in "
            + "<foreach item='item' index='index' collection='orgids'      open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>")
    List<Person> getPersonListByOrgIds(@Param("orgids") List<String> orgids);
    @Select("<script>"
            + "select distinct per.* from person per left join personorg po on per.id = po.personid left join personrole pr on per.id = pr.personid  where pr.roleid= #{roleid} and po.orgid in  "
            + "<foreach item='item' index='index' collection='orgids'      open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>")
    List<Person> getPersonListByOrgIdsAndRoleId(@Param("orgids") List<String> orgids, @Param("roleid") String roleid);
}
